//---------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------//
//   Model
//---------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------//

#ifndef LIE_MODEL_H
#define LIE_MODEL_H

#include <SFML/Graphics.hpp>
#include <string>
#include <map>
#include "PausableClock.h"

struct Frame
{
    sf::Vector2f center;
    sf::IntRect subrect;
};
class Model
{
public:
    Model();
    Model(const std::string& filename);
    virtual ~Model();

    virtual bool loadModel(const std::string& filename);
    sf::Sprite getCurrentSprite() const;
    void setSpriteCenter(const sf::Vector2f& center);
	void setSpriteRotation(float angle);
    void setSpritePosition(const sf::Vector2f& position);
    void setSpriteSubRect(const sf::IntRect& subrect);
	void setOpacity(int opacity);
	void flipX(bool flip);

    void changeFrame(unsigned int frame);
    unsigned int currentFrame() const;
    void nextFrame();
    void reset();

    void loop(bool choice);
    bool isLoop() const;

    void play();
    void stop();
    void stopGroup();
    void pause();
    bool isPlaying() const;

    void setDelay(const float &delay);
    float delay() const;
    void update();

    unsigned int getSize();

    void setGroup(const std::string& group);
    const std::string& getGroup() const;
    void addGroup(const std::string& name, const sf::Vector2i& frames);

	void setVisible(bool visible);
	void addAnchor(int frame, const std::string& name, const sf::Vector2f& position);
	sf::Vector2f getAnchor(const std::string& name);

protected:
    sf::Sprite mpt_sprite;
    std::map<int, Frame> mpt_frames;
	std::map<int, std::map<std::string, sf::Vector2f> > mpt_anchors;
    std::map<std::string, sf::Vector2i> mpt_groups;
    std::string mpt_currentGroup;

    PausableClock mpt_clock;
    unsigned int mpt_frameCount;
	float mpt_delay;
	bool mpt_isLoop;
	bool mpt_play;
	bool mpt_visible;
};


#endif




